import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import Icons from "unplugin-icons/vite";
import IconsResolver from "unplugin-icons/resolver";

// https://vite.dev/config/
export default defineConfig({
  base: "./",
  plugins: [
    vue(),
    // 移除 vueDevTools() 插件
    AutoImport({
      imports: ["vue", "vue-router"],
      resolvers: [ElementPlusResolver()],
      dts: "./src/auto-imports.d.ts",
    }),
    Components({
      dirs: ["src/views/"],
      extensions: ["vue", "md"],
      resolvers: [
        ElementPlusResolver({
          importStyle: "sass",
        }),
        IconsResolver(),
      ],
      dts: "./src/components.d.ts",
    }),
    Icons({
      autoInstall: true,
      compiler: "vue3",
    }),
  ],
  server: {
    host: "0.0.0.0",
    port: 3000,
    open: true,
    proxy: {
      // "/api": {
      //   target: "http://localhost:5000",
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace(/^\/api/, ""),
      // },
      // "/files": {
      //   target: "http://192.168.1.200:18080",
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace(/^\/files/, ""),
      // },
      // "/apig": {
      //   target: "http://127.0.0.1:5000",
      //   changeOrigin: true,
      //   rewrite: (path) => path.replace(/^\/apig/, ""),
      // },
    },
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/assets/element-ui.scss" as *;`,
        api: "modern-compiler",
      },
    },
  },
});